<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String picBasePath="http://106.53.67.228";
%>
<link rel="stylesheet" href="<c:url value="/pager/css/pages.css" />">
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- 页面meta -->
    <meta charset="utf-8">
    <title>小说管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta
            content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
            name="viewport">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath }/static/css/admin_other_css/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath }/static/css/admin_other_css/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath }/static/css/admin_other_css/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath }/static/css/admin_other_css/style.css">
    <script
            src="${pageContext.request.contextPath }/static/css/admin_other_css/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script
            src="${pageContext.request.contextPath }/static/css/admin_other_css/plugins/bootstrap/js/bootstrap.min.js"></script>
    <style type="text/css">
        #page_container {
            width: 1150px;
            height: 50px;
            border-radius: 20px;
            display: flex;
            align-items: center;
            font-size: 30px;
            justify-content: center;
        }

        #page_container > div {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            margin-left: 70px;
            text-align: center;
            line-height: 40px;
        }
    </style>
    <title>Insert title here</title>
</head>
<body>
<c:if test="${flag == 'change' }">
    <script type='text/javascript'>
        alert('修改成功！');
    </script>
</c:if>
<c:if test="${flag == 'add' }">
    <script type='text/javascript'>
        alert('添加成功！');
    </script>
</c:if>
<div class="box-header with-border">
    <h3 class="box-title">小说详情(点击小说封面可以查看小说章节详情)</h3>
</div>

<div class="box-body">

    <!-- 数据表格 -->
    <div class="table-box">

        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="添加"
                            data-toggle="modal" data-target="#editModal">
                        <i class="fa fa-file-o"></i> 添加
                    </button>
                    <button type="button" class="btn btn-default" title="添加txt" id="btn_addtxt"
                            data-toggle="modal" data-target="#editModaltxt">
                        <i class="fa fa-file-o"></i> 添加(更新)总zip
                    </button>
                    <button type="button" class="btn btn-default" title="添加txt" id="btn_addchapter"
                            data-toggle="modal" data-target="#editChapterTxt">
                        <i class="fa fa-file-o"></i> 分章节添加txt
                    </button>
                    <button type="button" class="btn btn-default" id="btn_logicdelete"
                            title="删除">
                        <i class="fa fa-ban"></i> 删除(可批量)
                    </button>
                    <button type="button" class="btn btn-default" id="btn_refresh"
                            title="刷新">
                        <i class="fa fa-ban"></i>刷新
                    </button>
                    <button type="button" class="btn btn-default" id="btn_lookDeleted"
                            title="查看已删除项">
                        <i class="fa fa-ban"></i>查看已删除项
                    </button>
                </div>
            </div>
        </div>
        <div class="box-tools pull-right">
            <div class="has-feedback">
                <form
                        action="${pageContext.request.contextPath }/admin/getAllNovels"
                        method="post">
                    <input type="hidden" name="method" id="method" value="search"/>
                    小说名称：<input type="text" id="pro_name" name="novel.novelname"/> <input
                        type="submit" name="search" id="search" value="查询"/>
                </form>
            </div>
        </div>
        <!--工具栏/-->

        <!--数据列表-->
        <table id="dataList"
               class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th style="padding-right: 0px"><input id="selall"
                                                      type="checkbox" class="icheckbox_square-blue"></th>
                <th style="text-align: center; vertical-align: middle;"
                    class="sorting">小说名称
                </th>
                <th style="text-align: center; vertical-align: middle; width: 120px;"
                        class="sorting">小说作者
                </th>
                <th style="text-align: center; vertical-align: middle; width: 120px;"
                    class="sorting">是否为会员书籍
                </th>
                <th style="text-align: center; vertical-align: middle;"
                    class="sorting">小说封面
                </th>
                <th style="text-align: center; vertical-align: middle;"
                    class="sorting">小说类别
                </th>
                <th style="text-align: center; vertical-align: middle;"
                    class="sorting">小说描述
                </th>
                <th style="text-align: center; vertical-align: middle;"
                    class="sorting">小说下载量
                </th>
                <th style="text-align: center; vertical-align: middle;"
                    class="sorting">小说评分
                </th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageBean.beanList }" var="m">
                <c:if test="${m.isDelete==0}">
                <tr>
                    <td class="td">
                        <input type="checkbox" id="checkbox_n"
                                          class="pro" value="${m.id }">
                    </td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.novelname }</td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.artist }</td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.isFree }</td>
                    <td class="td" style="width: 120px;"><a href="${pageContext.request.contextPath }/admin/getAllChapter/${m.id}"><img
                            src="<%= picBasePath%>/${m.pic }"
                            style="width: 120px;"/></a></td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.typeId }</td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.detail }</td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.dcounts }</td>
                    <td style="text-align: center; vertical-align: middle;"
                        class="td">${m.avgscore }</td>
                </tr>
                </c:if>
            </c:forEach>
            </tbody>
        </table>
        <!--数据列表/-->
        <div class="htmleaf-content" style="position: relative;padding:5px;">
            共${pageBean.info.total}条记录，当前显示第&nbsp;${pageBean.info.pageNum}/${pageBean.info.pages}&nbsp;页
            <ul class="manu" style="position:absolute;right:0px;top:0px;">
                <c:if test="${!pageBean.info.isFirstPage}">
                    <li><a href="<c:url value="/admin/getAllNovels" />?pc=1${pageBean.url}">首页</a></li>
                    <li>
                        <a href="<c:url value="/admin/getAllNovels" />?pc=${pageBean.info.prePage}${pageBean.url}">上一页</a>
                    </li>
                </c:if>
                <c:forEach items="${pageBean.info.navigatepageNums}" var="navigatepageNum">
                    <c:if test="${navigatepageNum==pageBean.info.pageNum}">
                        <li class="active"><a
                                href="<c:url value="/admin/getAllNovels" />?pc=${navigatepageNum}${pageBean.url}">${navigatepageNum}</a>
                        </li>
                    </c:if>
                    <c:if test="${navigatepageNum!=pageBean.info.pageNum}">
                        <li>
                            <a href="<c:url value="/admin/getAllNovels" />?pc=${navigatepageNum}${pageBean.url}">${navigatepageNum}</a>
                        </li>
                    </c:if>
                </c:forEach>
                <c:if test="${!pageBean.info.isLastPage}">
                    <li>
                        <a href="<c:url value="/admin/getAllNovels" />?pc=${pageBean.info.nextPage}${pageBean.url}">下一页</a>
                    </li>
                    <li>
                        <a href="<c:url value="/admin/getAllNovels" />?pc=${pageBean.info.lastPage}${pageBean.url}">最后一页</a>
                    </li>
                </c:if>
            </ul>
        </div>
        <!--数据列表/-->
    </div>
    <!-- 数据表格 /-->

</div>
<!-- /.box-body -->
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" name="editModal" tabindex="-1"
     role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h3 id="myModalLabel">添加小说</h3>
            </div>
            <div class="modal-body">
                <form id="form1" enctype="multipart/form-data"
                      action="${pageContext.request.contextPath }/admin/addNewNovel"
                      method="post">
                    <table class="table table-bordered table-striped" width="800px">
                        <tr>
                            <td>小说名称</td>
                            <td><input name="novelname" class="form-control"
                                       placeholder="小说名称"></td>
                        </tr>
                        <tr>
                            <td>小说作者</td>
                            <td><input name="artist" class="form-control"
                                       placeholder="小说作者"></td>
                        </tr>
                        <tr>
                            <td>小说类别</td>
                            <td><input name="typeId" class="form-control"
                                       placeholder="小说类别"></td>
                        </tr>
                        <tr>
                            <td>小说描述</td>
                            <td><input name="detail" class="form-control"
                                       placeholder="小说描述"></td>
                        </tr>
                        <tr>
                            <td>是否为会员书籍</td>
                            <td><input name="isFree" class="form-control"
                                       placeholder="是否为会员书籍"></td>
                        </tr>
                        <tr>
                            <td>小说封面</td>
                            <td><input type=file name="file" multiple="multiple"
                                       placeholder="小说封面"></td>
                        </tr>
                    </table>
                </form>

            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" id="add"
                        aria-hidden="true">保存
                </button>
                <button class="btn btn-default" data-dismiss="modal"
                        aria-hidden="true">关闭
                </button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="editModaltxt" name="editModaltxt" tabindex="-1"
     role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h3>添加小说zip</h3>
            </div>
            <div class="modal-body">
                <form id="form2" enctype="multipart/form-data"
                      action="${pageContext.request.contextPath }/admin/addNewNoveltxt"
                      method="post">
                    <table class="table table-bordered table-striped" width="800px">
                        <tr>
                            <td>小说zip</td>
                            <td><input type=file name="file" multiple="multiple"
                                       placeholder="小说zip"></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" id="addtxt"
                        aria-hidden="true">保存
                </button>
                <button class="btn btn-default" data-dismiss="modal"
                        aria-hidden="true">关闭
                </button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="editChapterTxt" name="editChapterTxt" tabindex="-1"
     role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h3>分章节添加txt</h3>
            </div>
            <div class="modal-body">
                <form id="form3" enctype="multipart/form-data"
                      action="${pageContext.request.contextPath }/admin/addTxtByChapter"
                      method="post">
                    <table class="table table-bordered table-striped" width="800px">
                        <tr>
                            <td>章节txt</td>
                            <td><input type=file name="file" multiple="multiple"
                                       placeholder="章节txt"></td>
                        </tr>
                        <tr>
                            <td>章节名称</td>
                            <td><input name="chaptername" class="form-control"
                                       placeholder="章节名称"></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" id="addtxtbychapter"
                        aria-hidden="true">保存
                </button>
                <button class="btn btn-default" data-dismiss="modal"
                        aria-hidden="true">关闭
                </button>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    $('#add').click(function () {
        $('#form1').submit();
    });



    $("#btn_lookDeleted").click(function () {
        window.location.href="${pageContext.request.contextPath }/admin/getAllDeltedNovels";
    })

    $('#btn_logicdelete').click(function () {

        var sum = 0;
        $('.pro').each(function () {
            if ($(this).prop('checked')) {
                sum++;
            }
        })
        if (sum ==0) {
            alert('请至少选择一项!');
            return false;
        }else{
            var arr=new Array();
            $(".pro").each(function () {
                if($(this).prop("checked")){
                    var id=$(this).val();
                    arr.push(id);
                }
            })
            window.location.href="${pageContext.request.contextPath }/admin/logicDeleteNovel/"+arr;
        }
    });

    $('#selall').change(function () {
        if ($('#selall').prop('checked')) {
            $('.pro').each(function () {
                $(this).prop('checked', true);
            })
        } else {
            $('.pro').each(function () {
                $(this).prop('checked', false);
            })
        }
    })


    var id;
    $("#btn_addtxt").click(function () {
        var sum = 0;
        $('.pro').each(function () {
            if ($(this).prop('checked')) {
                id=$(this).val();
                sum++;
            }
        })
        if (sum !=1) {
            alert('请选择且仅选择一项!');
            return false;
        }else{
            return true;
        }
    });


    var id1;
    $("#btn_addchapter").click(function () {
        var sum = 0;
        $('.pro').each(function () {
            if ($(this).prop('checked')) {
                id1=$(this).val();
                sum++;
            }
        })
        if (sum !=1) {
            alert('请选择且仅选择一项!');
            return false;
        }else{
            return true;
        }
    });

    $("#addtxtbychapter").click(function () {
        $("#form3").prop("action","${pageContext.request.contextPath }/admin/addTxtByChapter/"+id1);
        $("#form3").submit();
    })

    $("#addtxt").click(function () {
        $("#form2").prop("action","${pageContext.request.contextPath }/admin/addNovelTxt/"+id);
        $("#form2").submit();
    });


    $('#btn_refresh')
        .click(
            function () {
                window.location.href = "${pageContext.request.contextPath }/admin/getAllNovels";
            })

</script>
</html>